package com.scrx.ymg.action;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.google.gson.Gson;
import com.scrx.ymg.entity.AgentDrawings;
import com.scrx.ymg.entity.AgentInfo;
import com.scrx.ymg.entity.AgentMoney;
import com.scrx.ymg.entity.AgentSuperMarketSet;
import com.scrx.ymg.entity.OtherInfo;
import com.scrx.ymg.entity.SuperMarketInfo;
import com.scrx.ymg.entity.User;
import com.scrx.ymg.service.agent.IAgentService;
import com.scrx.ymg.service.supermarket.ISuperMarketService;
import com.scrx.ymg.service.user.IUserService;

@Controller
@RequestMapping("/agentAction")
public class AgentAction {

	@Autowired
	private IAgentService agents;

	@Autowired
	private ISuperMarketService sms;

	@Autowired
	private IUserService us;

	/**
	 * 代理商查询超市开店设置
	 * 
	 * @param agentId
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getSuperMarketSetinfo", produces = "text/json;charset=UTF-8")
	public String getSuperMarketSetinfo(AgentSuperMarketSet set, int pageNum, int pageCount) {
		Map<Object, Object> map = agents.getSuperMarketSetinfo(set, pageNum, pageCount);
		Gson gson = new Gson();
		return gson.toJson(map);
	}
	
	/**
	 * 根据代理商所属区域编号查询代理商信息
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getAgentInfoByagentRegion", produces = "text/json;charset=UTF-8")
	public String getAgentInfoByagentRegion(String agentRegion){
		AgentInfo info =agents.getAgentInfoByagentRegion(agentRegion);
		Gson gson = new Gson();
		return gson.toJson(info);
	}
	/**
	 * 根据代理商id查询代理商信息
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getAgentInfoById", produces = "text/json;charset=UTF-8")
	public String getAgentInfoById(Integer agentId){
		AgentInfo info =agents.getAgentInfo(agentId);
		Gson gson = new Gson();
		return gson.toJson(info);
	}
	
	/**
	 * 根据代理商所属区域编号查询正常营业代理商信息
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getAgentInfoByagentRegionAndStatus", produces = "text/json;charset=UTF-8")
	public String getAgentInfoByagentRegionAndStatus(String agentRegion){
		AgentInfo info =agents.getAgentInfoByagentRegionAndStatus(agentRegion);
		Gson gson = new Gson();
		return gson.toJson(info);
	}

	/**
	 * 代理商审核超市开店设置
	 * @param agentId
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/agreeOrNotSuperMarketSet", produces = "text/json;charset=UTF-8")
	public String agreeOrNotSuperMarketSet(AgentSuperMarketSet set) {
		String msg = agents.agreeOrNotSuperMarketSet(set);
		return msg;
	}

	/**
	 * 冻结恢复超市
	 * @param account
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/freezeSuperMarket", produces = "text/json;charset=UTF-8")
	public String freezeSuperMarket(SuperMarketInfo info) {
		return sms.freezeSuperMarket(info);
	}

	/**
	 * 查询代理商所属超市
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getSuperMarketInfoList", produces = "text/json;charset=UTF-8")
	public String getSuperMarketInfoList(SuperMarketInfo info, int pageNum, int pageCount) {
		Map<Object, Object> map = agents.getSuperMarketInfoList(info, pageNum, pageCount);
		Gson gson = new Gson();
		return gson.toJson(map);
	}

	/**
	 * 得到代理商营业额
	 * 
	 * @param superId
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getAgentMoneyInfo", produces = "text/json;charset=UTF-8")
	public String getAgentMoneyInfo(int agentId) {
		AgentMoney money = agents.getAgentMoneyInfo(agentId);
		Gson gson = new Gson();
		return gson.toJson(money);
	}

	/**
	 * 代理商提现
	 * 
	 * @param superId
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/AgentWithdraw", produces = "text/json;charset=UTF-8")
	public String AgentWithdraw(AgentDrawings drawing) {
		String msg = sms.AgentWithdraw(drawing);
		Gson gson = new Gson();
		return gson.toJson(msg);
	}

	/**
	 * 查询代理商提现记录
	 * 
	 * @param drawing
	 * @param pageNum
	 * @param pageCount
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getAgentDrawings", produces = "text/json;charset=UTF-8")
	public String getAgentDrawings(AgentDrawings drawing, int pageNum, int pageCount) {
		Map<Object, Object> map = sms.getAgentDrawings(drawing, pageNum, pageCount);
		Gson gson = new Gson();
		return gson.toJson(map);
	}

	/**
	 * 查询用户信息
	 * 
	 * @param user
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getUserInfo", produces = "text/json;charset=UTF-8")
	public String getUserInfo(User user, int pageNum, int pageCount) {
		Map<Object, Object> map = us.getUserInfo(user, pageNum, pageCount);
		Gson gson = new Gson();
		return gson.toJson(map);
	}

	/**
	 * 查询代理商所属超市统计信息
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/statisticsSuperMarketInfo", produces = "text/json;charset=UTF-8")
	public String statisticsSuperMarketInfo(SuperMarketInfo info, int pageNum, int pageCount) {
		Map<Object, Object> map = agents.statisticsSuperMarketInfo(info, pageNum, pageCount);
		Gson gson = new Gson();
		return gson.toJson(map);
	}

	/**
	 * 新增代理商
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/addAgentInfo", produces = "text/json;charset=UTF-8")
	public String addAgentInfo(AgentInfo info) {
		return agents.addAgentInfo(info);
	}
	
	/**
	 * 恢复代理商
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/updateAgentInfo", produces = "text/json;charset=UTF-8")
	public String updateAgentInfo(AgentInfo info,String UUID) {
		return agents.updateAgentInfo(info,UUID);
	}

	/**
	 * 查询代理商
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectAgentInfoList", produces = "text/json;charset=UTF-8")
	public String selectAgentInfoList(AgentInfo info, int pageNum, int pageCount) {
		Map<Object, Object> map = agents.selectAgentInfoList(info, pageNum, pageCount);
		Gson gson = new Gson();
		return gson.toJson(map);
	}
	
	/**
	 * 冻结,恢复代理商
	 * @param info
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/changeStatusAgentInfo", produces = "text/json;charset=UTF-8")
	public String changeStatusAgentInfo(AgentInfo info){
		return agents.changeStatusAgentInfo(info);
	}
	
	/**
	 * 新建异业商家
	 * @param info
	 * @param sjsj 
	 * @param yyzz
	 * @param htxy
	 * @param card
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/insertOtherInfo", produces = "text/json;charset=UTF-8")
	public String insertOtherInfo(OtherInfo info,MultipartFile sjsj,MultipartFile yyzz
			,MultipartFile htxy,MultipartFile card){
		
		return agents.insertOtherInfo(info,sjsj,yyzz,htxy,card);
	}
	/**
	 * 更新异业商家状态:冻结.恢复
	 * @param info
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/updateOtherInfo", produces = "text/json;charset=UTF-8")
	public String updateOtherInfo(OtherInfo info){
		return agents.updateOtherInfo(info);
	}
	

}
